<?php
namespace app\index\Model;
use think\Model;
use catetree\Catetree;
class TpGoods extends Model
{


	//获取相关推荐位id下商品信息
	public function getGoodsRecpos($recposID){
		$GoodsRecpos=array();
		$_GoodsRecpos=db('tp_rec_item')->where(['recpos_id'=>$recposID,'value_type'=>1])->select();
		foreach ($_GoodsRecpos as $k => $v) {
			$arr=$this->where(['id'=>$v['value_id']])->find();
			if($arr){
				$GoodsRecpos[]=$arr;
			}
			
		}
		return $GoodsRecpos;
	}


	//获取首页推荐主分类下所有子分类下的推荐商品的信息，在首页展示
	public function getIndexRecposGoods($cateID,$recposID){
		$Catetree=new Catetree();
		$sonID=$Catetree->childrenids($cateID,db('tp_category'));//注意$sonID位静态数组
		$sonID[]=$cateID;
        //获取首页推荐的商品id
		$_recGoods=db('tp_rec_item')->where(['recpos_id'=>$recposID,'value_type'=>1])->select();
		$recGoods=array();
		foreach ($_recGoods as $k1 => $v1) {
			$recGoods[]=$v1['value_id'];
		}
		$map['category_id']=array('IN',$sonID);
		$map['id']=array('IN',$recGoods);
            //获取首页推荐下所有分类的推荐商品的信息
		$RecposGoods=db('tp_goods')->where($map)->limit(6)->order('id DESC')->select();
		return $RecposGoods;
		
	}

   
}
